package com.example.springboot.service;

import com.example.springboot.entity.Container;
import com.example.springboot.entity.ContainerExample;
import com.example.springboot.mapper.ContainerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: jyf2000jyf
 * @Date: 2022/5/23
 * @Time: 23:00
 * @Email: 904593011@qq.com
 * @Description:
 **/
@Service
public class AdminContainerServiceImpl implements AdminContainerService {

    @Autowired
    ContainerMapper containerMapper;

    @Override
    public List<Container> findAll(Integer pageNum, Integer pageSize, Integer yard) {
        ContainerExample example = new ContainerExample();
        ContainerExample.Criteria criteria = example.createCriteria();
        example.setOrderByClause("id asc limit " + pageNum + "," + pageSize);
        if (yard != null && !yard.equals(0)) {
            criteria.andYardEqualTo(yard);
        }
        return containerMapper.selectByExample(example);
    }

    @Override
    public Integer getAmount(Integer yard) {
        ContainerExample example = new ContainerExample();
        ContainerExample.Criteria criteria = example.createCriteria();
        if (yard != null && !yard.equals(0)) {
            criteria.andYardEqualTo(yard);
        }
        return (Integer) (int) containerMapper.countByExample(example);
    }
}
